import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    // 用户的主键值
    const id = ref(null)
    const setId = (newId) => {
      id.value = newId
    }

    // 用户手机号
    const phone = ref('')
    const setPhone = (newPhone) => {
      phone.value = newPhone
    }

    // 性别
    const sex = ref(null)
    const setSex = (newSex) => {
      sex.value = newSex
    }

    // 用户的头像
    const avatar = ref('')
    const setAvatar = (newAvatar) => {
      avatar.value = newAvatar
    }

    // 个人简介
    const intro = ref('')
    const setIntro = (newIntro) => {
      intro.value = newIntro
    }

    // 用户的昵称
    const nickName = ref('')
    const setNickName = (newNickName) => {
      nickName.value = newNickName
    }

    // 定位省份
    const province = ref('')
    const setProvince = (newProvince) => {
      province.value = newProvince
    }

    // 定位城市
    const city = ref('')
    const setCity = (newCity) => {
      city.value = newCity
    }

    // 用户的token
    const token = ref('')
    const setToken = (newToken) => {
      token.value = newToken
    }
    const removeToken = () => {
      token.value = ''
    }

    // 重置
    const reset = () => {
      id.value = null
      phone.value = ''
      sex.value = null
      avatar.value = ''
      intro.value = ''
      nickName.value = ''
      province.value = ''
      city.value = ''
      token.value = ''
    } 
    return {
      id, setId,
      phone, setPhone,
      sex, setSex,
      avatar, setAvatar,
      intro, setIntro,
      nickName, setNickName,
      province, setProvince,
      city, setCity,
      token, setToken, removeToken,
      reset
    }
  },
  {
    // 配置持久化
    persist: true
  }
)
